<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="HA集群," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;环境： &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;CentOS 6.5 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;MySQL_Master   &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#">
<meta name="keywords" content="HA集群">
<meta property="og:type" content="article">
<meta property="og:title" content="Mysql-5.5+Heartbeat-3.0.5+DRBD">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/HA集群/5. Mysql-5.5+Heartbeat-3.0.5+DRBD/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;环境： &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;CentOS 6.5 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;MySQL_Master   &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-01T08:50:09.959Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Mysql-5.5+Heartbeat-3.0.5+DRBD">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;环境： &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;CentOS 6.5 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;MySQL_Master   &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/HA集群/5. Mysql-5.5+Heartbeat-3.0.5+DRBD/"/>





  <title>Mysql-5.5+Heartbeat-3.0.5+DRBD | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/HA集群/5. Mysql-5.5+Heartbeat-3.0.5+DRBD/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Mysql-5.5+Heartbeat-3.0.5+DRBD</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T02:04:46+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;环境：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CentOS 6.5</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;MySQL_Master  </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;eth0  192.168.1.10</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;eth1  192.168.2.10        </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;MySQL_Slave    </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;eth0  192.168.1.11</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;eth1  192.168.2.11</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;HA    192.168.1.254</p>
<h2 id="创建RAID1-0组合-存储数据-四块硬盘"><a href="#创建RAID1-0组合-存储数据-四块硬盘" class="headerlink" title="创建RAID1+0组合[存储数据 四块硬盘]"></a>创建RAID1+0组合[存储数据 四块硬盘]</h2><h3 id="1-创建两块RAID1-4块硬盘、MySQL主从节点执行"><a href="#1-创建两块RAID1-4块硬盘、MySQL主从节点执行" class="headerlink" title="1.创建两块RAID1 [4块硬盘、MySQL主从节点执行]"></a>1.创建两块RAID1 [4块硬盘、MySQL主从节点执行]</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">[root@master ~]<span class="comment"># mdadm --create /dev/md0 --level=raid1 --raid-devices=2 /dev/sdb1 /dev/sdc1</span></div><div class="line">mdadm: Note: this array has metadata at the start and</div><div class="line"> may not be suitable as a boot device. If you plan to</div><div class="line"> store <span class="string">'/boot'</span> on this device please ensure that</div><div class="line"> your boot-loader understands md/v1.x metadata, or use</div><div class="line"> --metadata=0.90</div><div class="line">Continue creating array? y</div><div class="line">mdadm: Defaulting to version 1.2 metadata</div><div class="line">mdadm: array /dev/md0 started.</div><div class="line">[root@master ~]<span class="comment"># mdadm --create /dev/md1 --level=raid1 --raid-devices=2 /dev/sdb1 /dev/sdc1</span></div><div class="line">mdadm: Note: this array has metadata at the start and</div><div class="line"> may not be suitable as a boot device. If you plan to</div><div class="line"> store <span class="string">'/boot'</span> on this device please ensure that</div><div class="line"> your boot-loader understands md/v1.x metadata, or use</div><div class="line"> --metadata=0.90</div><div class="line">Continue creating array? y</div><div class="line">mdadm: Defaulting to version 1.2 metadata</div><div class="line">mdadm: array /dev/md1 started.</div></pre></td></tr></table></figure>
<h3 id="2-利用两个-RAID1-创建-RAID0"><a href="#2-利用两个-RAID1-创建-RAID0" class="headerlink" title="2.利用两个 RAID1 创建 RAID0"></a>2.利用两个 RAID1 创建 RAID0</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@CentOS ~]<span class="comment"># mdadm --create /dev/md2 --level=raid0 --raid-devices=2 /dev/md0 /dev/md1</span></div><div class="line">mdadm: Defaulting to version 1.2 metadata</div><div class="line">mdadm: array /dev/md2 started.</div></pre></td></tr></table></figure>
<h3 id="3-将raid信息写入配置文件"><a href="#3-将raid信息写入配置文件" class="headerlink" title="3.将raid信息写入配置文件"></a>3.将raid信息写入配置文件</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">[root@master ~]<span class="comment"># mdadm --detail --scan &gt; /etc/mdadm.conf </span></div><div class="line">[root@master ~]<span class="comment"># vi /etc/mdadm.conf</span></div><div class="line">ARRAY /dev/md0 metadata=1.2 name=CentOS:0 UUID=b4c4c7b4:0f9f6e60:7eb24578:29682c96</div><div class="line">devices /dev/sdb1 /dev/sdc1</div><div class="line">ARRAY /dev/md1 metadata=1.2 name=CentOS:1 UUID=f5afcda6:86847677:c752fcdd:fbb91e00</div><div class="line">devices /dev/sdd1 /dev/sde1</div><div class="line">ARRAY /dev/md2 metadata=1.2 name=CentOS:2 UUID=00f120ec:bab2f3fe:80d88cb9:3ee4b76b</div><div class="line">devices /dev/md0 /dev/md1</div></pre></td></tr></table></figure>
<h2 id="安装DRBD"><a href="#安装DRBD" class="headerlink" title="安装DRBD"></a>安装DRBD</h2><h3 id="1-解压并安装DRBD"><a href="#1-解压并安装DRBD" class="headerlink" title="1.解压并安装DRBD"></a>1.解压并安装DRBD</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">[root@master Linux]<span class="comment"># yum -y install gcc kernel-devel kernel-headers flex perl</span></div><div class="line">[root@master Linux]<span class="comment"># http://oss.linbit.com/drbd/8.4/drbd-8.4.4.tar.gz</span></div><div class="line">[root@master Linux]<span class="comment"># tar fzvx drbd-8.4.4.tar.gz</span></div><div class="line">[root@master Linux]<span class="comment"># cd drbd-8.4.4</span></div><div class="line">[root@master drbd-8.4.4]<span class="comment"># ./configure --prefix=/usr/local/drbd-8.4 --with-km</span></div><div class="line">[root@master drbd-8.4.4]<span class="comment"># make KDIR=/usr/src/kernels/2.6.32-358.el6.x86_64/</span></div><div class="line">[root@master drbd-8.4.4]<span class="comment"># make install</span></div><div class="line">[root@master drbd-8.4.4<span class="comment"># mkdir -p /usr/local/drbd-8.4/var/run/drbd</span></div><div class="line">[root@master drbd-8.4.4]<span class="comment"># cp /usr/local/drbd-8.4/etc/rc.d/init.d/drbd /etc/init.d/</span></div><div class="line">[root@master drbd-8.4.4]<span class="comment"># chkconfig --add drbd</span></div><div class="line">[root@master drbd-8.4.4]<span class="comment"># chkconfig drbd on</span></div></pre></td></tr></table></figure>
<h3 id="2-安装drbd模块"><a href="#2-安装drbd模块" class="headerlink" title="2.安装drbd模块"></a>2.安装drbd模块</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@master drbd-8.4.4]<span class="comment"># cd drbd</span></div><div class="line">[root@master drbd]<span class="comment"># make clean</span></div><div class="line">[root@master drbd]<span class="comment"># make KDIR=/usr/src/kernels/2.6.32-358.el6.x86_64/</span></div><div class="line">[root@master drbd]<span class="comment"># cp drbd.ko /lib/modules/2.6.32-358.el6.x86_64/kernel/lib/</span></div><div class="line">[root@master drbd]<span class="comment"># depmod</span></div></pre></td></tr></table></figure>
<h3 id="3-配置global-common-conf"><a href="#3-配置global-common-conf" class="headerlink" title="3.配置global_common.conf"></a>3.配置global_common.conf</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div></pre></td><td class="code"><pre><div class="line">[root@master drbd]<span class="comment"># cd /usr/local/drbd-8.4/etc/drbd.d/</span></div><div class="line">[root@master drbd.d]<span class="comment"># cp global_common.conf global_common.conf.bak</span></div><div class="line">[root@master drbd.d]<span class="comment"># vi global_common.conf</span></div><div class="line">global &#123;</div><div class="line">usage-count no;</div><div class="line">&#125;</div><div class="line">common &#123;</div><div class="line">handlers &#123;</div><div class="line">pri-on-incon-degr <span class="string">"/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b &gt; /proc/sysrq-trigger ; reboot -f"</span>;</div><div class="line">pri-lost-after-sb <span class="string">"/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b &gt; /proc/sysrq-trigger ; reboot -f"</span>;</div><div class="line"><span class="built_in">local</span>-io-error <span class="string">"/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o &gt; /proc/sysrq-trigger ; halt -f"</span>;</div><div class="line">fence-peer <span class="string">"/usr/lib/drbd/crm-fence-peer.sh"</span>;</div><div class="line">split-brain <span class="string">"/usr/lib/drbd/notify-split-brain.sh root"</span>;</div><div class="line">out-of-sync <span class="string">"/usr/lib/drbd/notify-out-of-sync.sh root"</span>;</div><div class="line">&#125;</div><div class="line">startup &#123;</div><div class="line">wfc-timeout 30;</div><div class="line">degr-wfc-timeout 30;</div><div class="line">outdated-wfc-timeout 30;</div><div class="line">&#125;</div><div class="line">disk &#123;</div><div class="line"><span class="comment">#磁盘读写速度与同步速率的30%</span></div><div class="line">resync-rate 30M;</div><div class="line">on-io-error detach;</div><div class="line">fencing resource-only;</div><div class="line">&#125;</div><div class="line">net &#123;</div><div class="line">protocol C;</div><div class="line">cram-hmac-alg sha1;</div><div class="line">shared-secret <span class="string">"mysql-ha"</span>;</div><div class="line">csums-alg sha1;</div><div class="line">verify-alg crc32c;</div><div class="line">&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="4-创建r0资源"><a href="#4-创建r0资源" class="headerlink" title="4.创建r0资源"></a>4.创建r0资源</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">[root@master drbd.d]<span class="comment"># vi r0.res</span></div><div class="line">resource r0&#123;</div><div class="line"> on master&#123;</div><div class="line"> device /dev/drbd0; <span class="comment">#逻辑设备的路径</span></div><div class="line"> disk /dev/md2; <span class="comment">#物理设备</span></div><div class="line"> address  192.168.2.10:7788;</div><div class="line"> meta-disk  internal;</div><div class="line"> &#125;</div><div class="line"> on slave&#123;</div><div class="line"> device /dev/drbd0;</div><div class="line"> disk /dev/md2;</div><div class="line"> address  192.168.2.11:7788;</div><div class="line"> meta-disk  internal;</div><div class="line"> &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="5-建立-drbd-resource"><a href="#5-建立-drbd-resource" class="headerlink" title="5.建立 drbd resource"></a>5.建立 drbd resource</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@master drbd.d]<span class="comment"># modprobe drbd</span></div><div class="line">[root@master drbd.d]<span class="comment"># drbdadm create-md r0</span></div><div class="line">[root@master drbd.d]<span class="comment"># drbdadm up r0</span></div></pre></td></tr></table></figure>
<h3 id="6-设置Primary-在master节点操作"><a href="#6-设置Primary-在master节点操作" class="headerlink" title="6.设置Primary [在master节点操作]"></a>6.设置Primary [在master节点操作]</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@master drbd.d]<span class="comment"># drbdadm primary --force r0</span></div></pre></td></tr></table></figure>
<h3 id="7-创建DRBD文件系统-在Mysql主节点的master上执行"><a href="#7-创建DRBD文件系统-在Mysql主节点的master上执行" class="headerlink" title="7.创建DRBD文件系统 [在Mysql主节点的master上执行]"></a>7.创建DRBD文件系统 [在Mysql主节点的master上执行]</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@master drbd.d]<span class="comment"># mkfs.ext4 /dev/drbd0</span></div><div class="line">[root@master drbd.d]<span class="comment"># mount /dev/drbd0 /raid10/</span></div></pre></td></tr></table></figure>
<h3 id="8-DRBD同步测试"><a href="#8-DRBD同步测试" class="headerlink" title="8.DRBD同步测试"></a>8.DRBD同步测试</h3><h4 id="首先，在主服务器上先将设备卸载，同时将主服务器降为备用服务器："><a href="#首先，在主服务器上先将设备卸载，同时将主服务器降为备用服务器：" class="headerlink" title="首先，在主服务器上先将设备卸载，同时将主服务器降为备用服务器："></a>首先，在主服务器上先将设备卸载，同时将主服务器降为备用服务器：</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@master drbd]<span class="comment"># mkdir -p /raid10/mysql/data</span></div><div class="line">[root@master drbd]<span class="comment"># cd /</span></div><div class="line">[root@master /]<span class="comment"># umount /dev/drbd0</span></div><div class="line">[root@master /]<span class="comment"># drbdadm secondary r0</span></div></pre></td></tr></table></figure>
<h4 id="然后，登录备用服务器，将备用服务器升为主服务器，同时挂载drbd0设备到-raid10目录："><a href="#然后，登录备用服务器，将备用服务器升为主服务器，同时挂载drbd0设备到-raid10目录：" class="headerlink" title="然后，登录备用服务器，将备用服务器升为主服务器，同时挂载drbd0设备到 /raid10目录："></a>然后，登录备用服务器，将备用服务器升为主服务器，同时挂载drbd0设备到 /raid10目录：</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@slave drbd]<span class="comment"># drbdadm up r0</span></div><div class="line">[root@slave drbd]<span class="comment"># drbdadm primary r0</span></div><div class="line">[root@slave drbd]<span class="comment"># mount /dev/drbd0 /raid10/</span></div><div class="line">[root@slave drbd]<span class="comment"># cd /raid10/</span></div><div class="line">[root@slave raid10]<span class="comment"># ls</span></div><div class="line">lost+found mysql</div></pre></td></tr></table></figure>
<h2 id="使用中出现脑裂以及解决办法"><a href="#使用中出现脑裂以及解决办法" class="headerlink" title="使用中出现脑裂以及解决办法"></a>使用中出现脑裂以及解决办法</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@slave ~]<span class="comment"># cat /proc/drbd</span></div><div class="line">version: 8.4.4 (api:1/proto:86-101)</div><div class="line">GIT-hash: 599f286440bd633d15d5ff985204aff4bccffadd build by root@slave, 2013-12-03 09:50:30 0: cs:StandAlone ro:Primary/Unknown ds:UpToDate/Outdated r-----</div><div class="line">ns:0 nr:0 dw:2 dr:1684 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:4</div></pre></td></tr></table></figure>
<h3 id="查看日志"><a href="#查看日志" class="headerlink" title="查看日志"></a>查看日志</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">[root@slave /]<span class="comment"># tail -f /var/log/messages</span></div><div class="line">Dec  3 11:06:05 slave kernel: block drbd0: helper <span class="built_in">command</span>: /sbin/drbdadm split-brain minor-0 <span class="built_in">exit</span> code</div><div class="line">127 (0x7f00)</div><div class="line">Dec  3 11:06:05 slave kernel: drbd r0: conn( WFReportParams -&gt; Disconnecting )</div><div class="line">Dec  3 11:06:05 slave kernel: drbd r0: error receiving ReportState, e: -5 l: 0!</div><div class="line">Dec  3 11:06:05 slave kernel: drbd r0: asender terminated</div><div class="line">Dec  3 11:06:05 slave kernel: drbd r0: Terminating drbd_a_r0</div><div class="line">Dec  3 11:06:05 slave kernel: drbd r0: Connection closed</div><div class="line">Dec  3 11:06:05 slave kernel: drbd r0: conn( Disconnecting -&gt; StandAlone )</div><div class="line">Dec  3 11:06:05 slave kernel: drbd r0: receiver terminated</div><div class="line">Dec  3 11:06:05 slave kernel: drbd r0: Terminating drbd_r_r0</div><div class="line">Dec  3 11:06:41 slave kernel: block drbd0: role( Secondary -&gt; Primary )</div></pre></td></tr></table></figure>
<h2 id="解决方法："><a href="#解决方法：" class="headerlink" title="解决方法："></a>解决方法：</h2><h3 id="1-需要将现在的master角色修改为secondary"><a href="#1-需要将现在的master角色修改为secondary" class="headerlink" title="1.需要将现在的master角色修改为secondary"></a>1.需要将现在的master角色修改为secondary</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@master ~]<span class="comment"># drbdadm secondary r0</span></div><div class="line"><span class="comment">#该命令告诉slave，secondary上的数据不正确，以primary上的数据为准。</span></div><div class="line">[root@master ~]<span class="comment"># drbdadm -- --discard-my-data connect r0</span></div></pre></td></tr></table></figure>
<h3 id="2-我们还需要在slave上执行下面操作"><a href="#2-我们还需要在slave上执行下面操作" class="headerlink" title="2.我们还需要在slave上执行下面操作"></a>2.我们还需要在slave上执行下面操作</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#这样master就能和slave开始连接上了，并且保证数据不会丢失：</span></div><div class="line">[root@slave ~]<span class="comment"># drbdadm connect r0</span></div><div class="line">[root@slave ~]<span class="comment"># cat /proc/drbd</span></div><div class="line">version: 8.4.4 (api:1/proto:86-101)</div><div class="line">GIT-hash: 599f286440bd633d15d5ff985204aff4bccffadd build by root@slave, 2013-12-03 09:50:30</div><div class="line"> 0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----</div><div class="line"> ns:0 nr:4 dw:6 dr:1688 al:1 bm:1 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0</div><div class="line">[root@master ~]<span class="comment"># cat /proc/drbd</span></div><div class="line">version: 8.4.4 (api:1/proto:86-101)</div><div class="line">GIT-hash: 599f286440bd633d15d5ff985204aff4bccffadd build by root@master, 2013-12-03 09:49:22</div><div class="line"> 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----</div><div class="line"> ns:4 nr:0 dw:1 dr:1015 al:1 bm:1 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0</div></pre></td></tr></table></figure>
<h2 id="安装mysql"><a href="#安装mysql" class="headerlink" title="安装mysql"></a>安装mysql</h2><h3 id="1-mastr节点"><a href="#1-mastr节点" class="headerlink" title="1.mastr节点"></a>1.mastr节点</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">[root@master Linux]<span class="comment"># yum install gcc gcc-c++ autoconf automake ncurses-devel libtool-ltdl-devel* -y</span></div><div class="line">[root@master Linux]<span class="comment"># useradd -M -s /sbin/nologin mysql</span></div><div class="line">[root@master Linux]<span class="comment"># tar zfvx cmake-2.8.12.tar.gz</span></div><div class="line">[root@master Linux]<span class="comment"># cd cmake-2.8.12</span></div><div class="line">[root@master cmake-2.8.12]<span class="comment"># ./configure</span></div><div class="line">[root@master cmake-2.8.12]<span class="comment"># gmake &amp;&amp; make install</span></div><div class="line">[root@master cmake-2.8.12]<span class="comment"># cd ..</span></div><div class="line">[root@master Linux]<span class="comment"># tar zfxv mysql-5.5.25.tar.gz</span></div><div class="line">[root@master Linux]<span class="comment"># cd mysql-5.5.25</span></div><div class="line">[root@master mysql-5.5.25]<span class="comment"># cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5</span></div><div class="line">[root@master mysql-5.5.25]<span class="comment"># make &amp;&amp; make install</span></div><div class="line">[root@master mysql-5.5.25]<span class="comment"># cp support-files/my-medium.cnf /raid10/mysql/my.cf</span></div><div class="line">[root@master mysql-5.5.25]<span class="comment"># rm -rf /etc/my.cnf</span></div><div class="line">[root@master mysql-5.5.25]<span class="comment"># ln -sv /raid10/mysql/my.cf /etc/</span></div><div class="line">[root@master mysql-5.5.25]<span class="comment"># cd /usr/local/mysql-5.5/</span></div><div class="line">[root@master mysql-5.5]<span class="comment"># chown -R root:mysql .</span></div><div class="line">[root@master mysql-5.5]<span class="comment"># chown -R mysql:mysql /raid10/mysql/data/</span></div><div class="line">[root@master mysql-5.5]<span class="comment"># ./scripts/mysql_install_db --user=mysql \</span></div><div class="line">--basedir=/usr/<span class="built_in">local</span>/mysql-5.5/ \</div><div class="line">--datadir=/raid10/mysql/data/</div><div class="line">[root@master mysql-5.5]<span class="comment"># cp support-files/mysql.server /etc/init.d/mysqld</span></div><div class="line">[root@master mysql-5.5]<span class="comment"># chmod +x /etc/init.d/mysqld</span></div><div class="line">[root@master mysql-5.5]<span class="comment"># chkconfig --add mysqld</span></div><div class="line">[root@master mysql-5.5]<span class="comment"># vi /etc/init.d/mysqld</span></div><div class="line">datadir=/raid10/mysql/data</div></pre></td></tr></table></figure>
<h3 id="2-savle节点安装"><a href="#2-savle节点安装" class="headerlink" title="2.savle节点安装"></a>2.savle节点安装</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">——安装mysql[MySQL主节点的savle节点安装]</div><div class="line">[root@slave Linux]<span class="comment"># yum install gcc gcc-c++ autoconf automake ncurses-devel libtool-ltdl-devel* -y</span></div><div class="line">[root@slaveLinux]<span class="comment"># useradd -M -s /sbin/nologin mysql</span></div><div class="line">[root@slave Linux]<span class="comment"># tar zfvx cmake-2.8.12.tar.gz</span></div><div class="line">[root@slave Linux]<span class="comment"># cd cmake-2.8.12</span></div><div class="line">[root@slavecmake-2.8.12]<span class="comment"># ./configure</span></div><div class="line">[root@slavecmake-2.8.12]<span class="comment"># gmake &amp;&amp; make install</span></div><div class="line">[root@slavecmake-2.8.12]<span class="comment"># cd ..</span></div><div class="line">[root@slave Linux]<span class="comment"># tar zfxv mysql-5.5.25.tar.gz</span></div><div class="line">[root@slave Linux]<span class="comment"># cd mysql-5.5.25</span></div><div class="line">[root@slave mysql-5.5.25]<span class="comment"># cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5</span></div><div class="line">[root@slave mysql-5.5.25]<span class="comment"># make &amp;&amp; make install</span></div><div class="line">[root@slave mysql-5.5.25]<span class="comment"># cd /usr/local/mysql-5.5/</span></div><div class="line">[root@slave mysql-5.5]<span class="comment"># chown -R root:mysql .</span></div><div class="line">[root@slave mysql-5.5]<span class="comment"># cp support-files/mysql.server /etc/init.d/mysqld</span></div><div class="line">[root@slave mysql-5.5]<span class="comment"># vi /etc/init.d/mysqld</span></div><div class="line">datadir=/raid10/mysql/data</div></pre></td></tr></table></figure>
<h2 id="MySQL主节点实现高可用"><a href="#MySQL主节点实现高可用" class="headerlink" title="MySQL主节点实现高可用"></a>MySQL主节点实现高可用</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意：以下操作在MySQL主节点的master、slave节点执行</p>
<h3 id="1-添加hosts主机信息"><a href="#1-添加hosts主机信息" class="headerlink" title="1.添加hosts主机信息"></a>1.添加hosts主机信息</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@master Linux]<span class="comment"># vi /etc/hosts</span></div><div class="line">192.168.2.10  master</div><div class="line">192.168.2.11  slave</div></pre></td></tr></table></figure>
<h3 id="2-添加用户和组"><a href="#2-添加用户和组" class="headerlink" title="2.添加用户和组"></a>2.添加用户和组</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@master Linux]<span class="comment"># groupadd haclient</span></div><div class="line">[root@master Linux]<span class="comment"># useradd -g haclient -M -s /sbin/nologin hacluster</span></div></pre></td></tr></table></figure>
<h3 id="3-安装heartbeat"><a href="#3-安装heartbeat" class="headerlink" title="3.安装heartbeat"></a>3.安装heartbeat</h3><h4 id="安装相关软件依赖包"><a href="#安装相关软件依赖包" class="headerlink" title="安装相关软件依赖包"></a>安装相关软件依赖包</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">[root@master Linux]<span class="comment"># yum install libtool automake autoconf \</span></div><div class="line">glib2-devel \</div><div class="line">libxml2-devel \</div><div class="line">bzip2-devel \</div><div class="line">libtool-ltdl-devel \</div><div class="line">libxslt-devel \</div><div class="line">docbook* -y</div></pre></td></tr></table></figure>
<h4 id="安装glue"><a href="#安装glue" class="headerlink" title="安装glue"></a>安装glue</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@master Linux]<span class="comment"># wget http://hg.linux-ha.org/glue/archive/glue-1.0.9.tar.bz2</span></div><div class="line">[root@master Linux]<span class="comment"># tar jfvx glue-1.0.9.tar.bz2</span></div><div class="line">[root@master Linux]<span class="comment"># cd Reusable-Cluster-Components-glue--glue-1.0.9/</span></div><div class="line">[root@master Reusable-Cluster-Components-glue--glue-1.0.9]<span class="comment"># ./autogen.sh</span></div><div class="line">[root@master Reusable-Cluster-Components-glue--glue-1.0.9]<span class="comment"># ./configure LIBS='/lib64/libuuid.so.1'</span></div><div class="line">[root@CentOS Reusable-Cluster-Components-glue--glue-1.0.9]<span class="comment"># make &amp;&amp; make install</span></div></pre></td></tr></table></figure>
<h4 id="安装agents"><a href="#安装agents" class="headerlink" title="安装agents"></a>安装agents</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">[root@master Heartbeat-3-0-7e3a82377fa8]<span class="comment"># cd ..</span></div><div class="line">[root@master Linux]<span class="comment"># wget https://codeload.github.com/ClusterLabs/resource-agents/legacy.tar.gz/v3.9.2</span></div><div class="line">[root@master Linux]<span class="comment"># tar zfvx ClusterLabs-resource-agents-v3.9.2-0-ge261943.tar.gz</span></div><div class="line">[root@master Linux]<span class="comment"># cd ClusterLabs-resource-agents-b735277/</span></div><div class="line">[root@master ClusterLabs-resource-agents-b735277]<span class="comment"># ./autogen.sh</span></div><div class="line">[root@master ClusterLabs-resource-agents-b735277]<span class="comment"># ./configure LIBS='/lib64/libuuid.so.1'</span></div><div class="line">[root@master ClusterLabs-resource-agents-b735277]<span class="comment"># make &amp;&amp; make install</span></div></pre></td></tr></table></figure>
<h4 id="安装heartbeat"><a href="#安装heartbeat" class="headerlink" title="安装heartbeat"></a>安装heartbeat</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">[root@master ClusterLabs-resource-agents-b735277]<span class="comment"># cd ..</span></div><div class="line">[root@master Linux]<span class="comment"># wget http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/7e3a82377fa8.tar.bz2</span></div><div class="line">[root@master Linux]<span class="comment"># tar jfvx heartbeat-3.0.5.tar.bz2</span></div><div class="line">[root@master Linux]<span class="comment"># cd Heartbeat-3-0-7e3a82377fa8/</span></div><div class="line">[root@master Heartbeat-3-0-7e3a82377fa8]<span class="comment"># ./bootstrap</span></div><div class="line">[root@master Heartbeat-3-0-7e3a82377fa8]<span class="comment"># ./ConfigureMe configure LIBS='/lib64/libuuid.so.1'</span></div><div class="line">[root@master Heartbeat-3-0-7e3a82377fa8]<span class="comment"># make &amp;&amp; make install</span></div></pre></td></tr></table></figure>
<h3 id="4-配置heartbeat"><a href="#4-配置heartbeat" class="headerlink" title="4.配置heartbeat"></a>4.配置heartbeat</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div></pre></td><td class="code"><pre><div class="line">[root@master Heartbeat-3-0-7e3a82377fa8]<span class="comment"># cd doc</span></div><div class="line">[root@master doc]<span class="comment"># cp authkeys haresources ha.cf /etc/ha.d/</span></div><div class="line">[root@master doc]<span class="comment"># cp /usr/etc/ha.d/shellfuncs /etc/ha.d/</span></div><div class="line">[root@master doc]<span class="comment"># rm -rf /usr/etc/ha.d</span></div><div class="line">[root@master doc]<span class="comment"># ln -sv /etc/ha.d /usr/etc</span></div><div class="line">[root@master doc]<span class="comment"># vi /etc/ha.d/ha.cf</span></div><div class="line"><span class="comment">#开启日志</span></div><div class="line">logfile /var/<span class="built_in">log</span>/ha-log</div><div class="line"><span class="comment">#设置syslog()/logger设备</span></div><div class="line">logfacility local0</div><div class="line"><span class="comment">#心跳发送时间间隔/秒</span></div><div class="line">keepalive 2</div><div class="line"><span class="comment">#15秒没有收到主机心跳、确认主机故障</span></div><div class="line">deadtime 15</div><div class="line"><span class="comment">#警告次数</span></div><div class="line">warntime 5</div><div class="line"><span class="comment">#守护进程启动30后 启动服务资源</span></div><div class="line">initdead 30</div><div class="line"><span class="comment">#监听端口</span></div><div class="line">udpport 694</div><div class="line"><span class="comment">#另一个节点IP、通过检测来保证心跳的可用性</span></div><div class="line">ucast eth0 192.168.1.11</div><div class="line">ucast eth1 192.168.2.11</div><div class="line"><span class="comment">#两个节点的名字 [uname -n 获取]</span></div><div class="line">node master</div><div class="line">node slave</div><div class="line"><span class="comment">#开启DPOD</span></div><div class="line">respawn hacluster /usr/lib64/heartbeat/ipfail</div><div class="line">respawn hacluster /usr/lib64/heartbeat/dopd</div><div class="line">apiauth ipfail gid=haclient uid=hacluster</div><div class="line">apiauth dopd gid=haclient uid=hacluster</div><div class="line">[root@master doc]<span class="comment"># vi /etc/ha.d/authkeys</span></div><div class="line">auth 1</div><div class="line">1 sha1 HI!</div><div class="line">[root@master doc]<span class="comment"># chmod 600 /etc/ha.d/authkeys</span></div><div class="line">[root@master doc]<span class="comment"># vi /etc/ha.d/haresources</span></div><div class="line">master drbddisk::r0 Filesystem::/dev/drbd0::/raid10::ext4 mysqld IPaddr::192.168.1.254/24/eth0</div><div class="line">[root@master doc]<span class="comment"># cd /Linux/drbd-8.4.4/scripts/</span></div><div class="line">[root@master scripts]<span class="comment"># cp drbddisk /etc/ha.d/resource.d/</span></div><div class="line">[root@master scripts]<span class="comment"># cp /etc/init.d/mysqld /etc/ha.d/resource.d/</span></div><div class="line">[root@master scripts]<span class="comment"># chkconfig --add heartbeat</span></div><div class="line">[root@master scripts]<span class="comment"># chkconfig heartbeat on</span></div></pre></td></tr></table></figure>
<h2 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h2><h3 id="1-启动master节点启动heartbeat"><a href="#1-启动master节点启动heartbeat" class="headerlink" title="1.启动master节点启动heartbeat"></a>1.启动master节点启动heartbeat</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@master scripts]<span class="comment"># /etc/init.d/heartbeat start</span></div></pre></td></tr></table></figure>
<h3 id="2-启动slave节点启动heartbeat"><a href="#2-启动slave节点启动heartbeat" class="headerlink" title="2.启动slave节点启动heartbeat"></a>2.启动slave节点启动heartbeat</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@slave scripts]<span class="comment"># /etc/init.d/heartbeat start</span></div></pre></td></tr></table></figure>
<h2 id="3-在master节点上查看启动日志"><a href="#3-在master节点上查看启动日志" class="headerlink" title="3.在master节点上查看启动日志"></a>3.在master节点上查看启动日志</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">[root@master ha.d]<span class="comment"># tail -f /var/log/ha-log</span></div><div class="line">Apr 26 21:11:48 master heartbeat: [42033]: info: Starting child client <span class="string">"/usr/lib64/heartbeat/ipfail"</span> (501,501)</div><div class="line">Apr 26 21:11:48 master heartbeat: [42033]: info: Starting child client <span class="string">"/usr/lib64/heartbeat/dopd"</span> (501,501)</div><div class="line">Apr 26 21:11:48 mster heartbeat: [42062]: info: Starting <span class="string">"/usr/lib64/heartbeat/ipfail"</span> as uid 501  gid 501 (pid 42062)</div><div class="line">Apr 26 21:11:48 mster heartbeat: [42064]: info: Starting <span class="string">"/usr/lib64/heartbeat/dopd"</span> as uid 501  gid 501 (pid 42064)</div><div class="line">Apr 26 21:11:48 mster heartbeat: [42061]: info: Local Resource acquisition completed.</div><div class="line">Apr 26 21:11:48 mster heartbeat: [42033]: info: Initial resource acquisition complete (req_our_resources)</div><div class="line">Apr 26 21:11:48 mster ipfail: [42062]: ERROR: auto_failback <span class="built_in">set</span> to incompatible legacy option.</div><div class="line">Apr 26 21:11:48 mster heartbeat: [42033]: WARN: Managed /usr/lib64/heartbeat/ipfail process 42062 exited with <span class="built_in">return</span> code 100.</div><div class="line">Apr 26 21:11:48 mster heartbeat: [42033]: info: Status update <span class="keyword">for</span> slave: status active</div><div class="line">harc[42104]:  2014/04/26_21:11:48 info: Running /usr/etc/ha.d//rc.d/status status</div><div class="line"><span class="comment">#说明启动成功</span></div></pre></td></tr></table></figure>
<h3 id="4-切换主备"><a href="#4-切换主备" class="headerlink" title="4.切换主备"></a>4.切换主备</h3><h4 id="在master节点停掉heartbeat"><a href="#在master节点停掉heartbeat" class="headerlink" title="在master节点停掉heartbeat"></a>在master节点停掉heartbeat</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@master scripts]<span class="comment"># /etc/init.d/heartbeat stop</span></div></pre></td></tr></table></figure>
<h4 id="查看slave日志是否能自动切换至slave节点"><a href="#查看slave日志是否能自动切换至slave节点" class="headerlink" title="查看slave日志是否能自动切换至slave节点"></a>查看slave日志是否能自动切换至slave节点</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div></pre></td><td class="code"><pre><div class="line">[root@slave scripts]<span class="comment"># tail -f /var/log/ha-log</span></div><div class="line"><span class="comment">#显示master节点已经shutdown</span></div><div class="line">Apr 26 21:21:27 slave heartbeat: [42054]: info: Received shutdown notice from <span class="string">'master'</span>.</div><div class="line">Apr 26 21:21:27 slave heartbeat: [42054]: info: Resources being acquired from master.</div><div class="line">harc[42118]:  2014/04/26_21:21:27 info: Running /usr/etc/ha.d//rc.d/status status</div><div class="line">Apr 26 21:21:27 slave heartbeat: [42119]: info: No <span class="built_in">local</span> resources [/usr/share/heartbeat/ResourceManager listkeys slave] to acquire.</div><div class="line">mach_down[42148]:  2014/04/26_21:21:27 info: Taking over resource group drbddisk::r0</div><div class="line">ResourceManager[42175]: 2014/04/26_21:21:27 info: Acquiring resource group: master drbddisk::r0 Filesystem::/dev/drbd0::/raid10::ext4 mysqld IPaddr::192.168.1.254/24/eth0</div><div class="line">ResourceManager[42175]: 2014/04/26_21:21:27 info: Running /etc/ha.d/resource.d/drbddisk r0 start</div><div class="line">Filesystem[42239]:  2014/04/26_21:21:27 INFO: Resource is stopped</div><div class="line">ResourceManager[42175]: 2014/04/26_21:21:27 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /raid10 ext4 start</div><div class="line">Filesystem[42320]:  2014/04/26_21:21:27 INFO: Running start <span class="keyword">for</span> /dev/drbd0 on /raid10</div><div class="line">Filesystem[42312]:  2014/04/26_21:21:28 INFO: Success</div><div class="line">ResourceManager[42175]: 2014/04/26_21:21:28 info: Running /etc/ha.d/resource.d/mysqld start</div><div class="line">Apr 26 21:21:39 slave heartbeat: [42054]: WARN: node master: is dead</div><div class="line">Apr 26 21:21:39 slave heartbeat: [42054]: info: Dead node master gave up resources.</div><div class="line">Apr 26 21:21:39 slave heartbeat: [42054]: info: Resources being acquired from master.</div><div class="line">Apr 26 21:21:39 slave heartbeat: [42054]: info: Link master:eth0 dead.</div><div class="line">Apr 26 21:21:39 slave heartbeat: [42054]: info: Link master:eth1 dead.</div><div class="line">Apr 26 21:21:41 slave heartbeat: [42614]: info: No <span class="built_in">local</span> resources [/usr/share/heartbeat/ResourceManager listkeys slave] to acquire.</div><div class="line">Apr 26 21:21:41 slave heartbeat: [42054]: info: Initial resource acquisition complete (req_our_resources)</div><div class="line">IPaddr[42642]:  2014/04/26_21:21:42 INFO: Resource is stopped</div><div class="line"><span class="comment">#显示slave节点的VIP已经运行</span></div><div class="line">ResourceManager[42175]: 2014/04/26_21:21:42 info: Running /etc/ha.d/resource.d/IPaddr 192.168.1.254/24/eth0 start</div><div class="line">IPaddr[42727]:  2014/04/26_21:21:42 INFO: Using calculated netmask <span class="keyword">for</span> 192.168.1.254: 255.255.255.0</div><div class="line">IPaddr[42727]:  2014/04/26_21:21:42 INFO: <span class="built_in">eval</span> ifconfig eth0:0 192.168.1.254 netmask 255.255.255.0 broadcast 192.168.1.255</div><div class="line">IPaddr[42701]:  2014/04/26_21:21:42 INFO: Success</div><div class="line">mach_down[42148]:  2014/04/26_21:21:42 info: mach_down takeover complete <span class="keyword">for</span> node master.</div><div class="line">harc[42820]:  2014/04/26_21:21:42 info: Running /usr/etc/ha.d//rc.d/status status</div><div class="line">mach_down[42837]:  2014/04/26_21:21:42 info: Taking over resource group drbddisk::r0</div><div class="line">ResourceManager[42864]: 2014/04/26_21:21:43 info: Acquiring resource group: master drbddisk::r0 Filesystem::/dev/drbd0::/raid10::ext4 mysqld IPaddr::192.168.1.254/24/eth0</div><div class="line"><span class="comment">#显示slave的mysql和drbd服务已经启动成功</span></div><div class="line">Filesystem[42906]:  2014/04/26_21:21:43 INFO: Running OK</div><div class="line">IPaddr[42987]:  2014/04/26_21:21:43 INFO: Running OK</div><div class="line">mach_down[42837]:  2014/04/26_21:21:43 info: mach_down takeover complete <span class="keyword">for</span> node master.</div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/HA集群/" rel="tag"># HA集群</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/HA集群/4. DRBD安装配置、工作原理及故障恢复/" rel="next" title="DRBD安装配置、工作原理及故障恢复">
                <i class="fa fa-chevron-left"></i> DRBD安装配置、工作原理及故障恢复
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/Linux安全/10. root账户不允许远程登陆/" rel="prev" title="root账户不允许远程登陆">
                root账户不允许远程登陆 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#创建RAID1-0组合-存储数据-四块硬盘"><span class="nav-number">1.</span> <span class="nav-text">创建RAID1+0组合[存储数据 四块硬盘]</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-创建两块RAID1-4块硬盘、MySQL主从节点执行"><span class="nav-number">1.1.</span> <span class="nav-text">1.创建两块RAID1 [4块硬盘、MySQL主从节点执行]</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-利用两个-RAID1-创建-RAID0"><span class="nav-number">1.2.</span> <span class="nav-text">2.利用两个 RAID1 创建 RAID0</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-将raid信息写入配置文件"><span class="nav-number">1.3.</span> <span class="nav-text">3.将raid信息写入配置文件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装DRBD"><span class="nav-number">2.</span> <span class="nav-text">安装DRBD</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-解压并安装DRBD"><span class="nav-number">2.1.</span> <span class="nav-text">1.解压并安装DRBD</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-安装drbd模块"><span class="nav-number">2.2.</span> <span class="nav-text">2.安装drbd模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-配置global-common-conf"><span class="nav-number">2.3.</span> <span class="nav-text">3.配置global_common.conf</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-创建r0资源"><span class="nav-number">2.4.</span> <span class="nav-text">4.创建r0资源</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-建立-drbd-resource"><span class="nav-number">2.5.</span> <span class="nav-text">5.建立 drbd resource</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-设置Primary-在master节点操作"><span class="nav-number">2.6.</span> <span class="nav-text">6.设置Primary [在master节点操作]</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-创建DRBD文件系统-在Mysql主节点的master上执行"><span class="nav-number">2.7.</span> <span class="nav-text">7.创建DRBD文件系统 [在Mysql主节点的master上执行]</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-DRBD同步测试"><span class="nav-number">2.8.</span> <span class="nav-text">8.DRBD同步测试</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#首先，在主服务器上先将设备卸载，同时将主服务器降为备用服务器："><span class="nav-number">2.8.1.</span> <span class="nav-text">首先，在主服务器上先将设备卸载，同时将主服务器降为备用服务器：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#然后，登录备用服务器，将备用服务器升为主服务器，同时挂载drbd0设备到-raid10目录："><span class="nav-number">2.8.2.</span> <span class="nav-text">然后，登录备用服务器，将备用服务器升为主服务器，同时挂载drbd0设备到 /raid10目录：</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用中出现脑裂以及解决办法"><span class="nav-number">3.</span> <span class="nav-text">使用中出现脑裂以及解决办法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#查看日志"><span class="nav-number">3.1.</span> <span class="nav-text">查看日志</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#解决方法："><span class="nav-number">4.</span> <span class="nav-text">解决方法：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-需要将现在的master角色修改为secondary"><span class="nav-number">4.1.</span> <span class="nav-text">1.需要将现在的master角色修改为secondary</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-我们还需要在slave上执行下面操作"><span class="nav-number">4.2.</span> <span class="nav-text">2.我们还需要在slave上执行下面操作</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装mysql"><span class="nav-number">5.</span> <span class="nav-text">安装mysql</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-mastr节点"><span class="nav-number">5.1.</span> <span class="nav-text">1.mastr节点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-savle节点安装"><span class="nav-number">5.2.</span> <span class="nav-text">2.savle节点安装</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MySQL主节点实现高可用"><span class="nav-number">6.</span> <span class="nav-text">MySQL主节点实现高可用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-添加hosts主机信息"><span class="nav-number">6.1.</span> <span class="nav-text">1.添加hosts主机信息</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-添加用户和组"><span class="nav-number">6.2.</span> <span class="nav-text">2.添加用户和组</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-安装heartbeat"><span class="nav-number">6.3.</span> <span class="nav-text">3.安装heartbeat</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#安装相关软件依赖包"><span class="nav-number">6.3.1.</span> <span class="nav-text">安装相关软件依赖包</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#安装glue"><span class="nav-number">6.3.2.</span> <span class="nav-text">安装glue</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#安装agents"><span class="nav-number">6.3.3.</span> <span class="nav-text">安装agents</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#安装heartbeat"><span class="nav-number">6.3.4.</span> <span class="nav-text">安装heartbeat</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-配置heartbeat"><span class="nav-number">6.4.</span> <span class="nav-text">4.配置heartbeat</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#测试"><span class="nav-number">7.</span> <span class="nav-text">测试</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-启动master节点启动heartbeat"><span class="nav-number">7.1.</span> <span class="nav-text">1.启动master节点启动heartbeat</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-启动slave节点启动heartbeat"><span class="nav-number">7.2.</span> <span class="nav-text">2.启动slave节点启动heartbeat</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-在master节点上查看启动日志"><span class="nav-number">8.</span> <span class="nav-text">3.在master节点上查看启动日志</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-切换主备"><span class="nav-number">8.1.</span> <span class="nav-text">4.切换主备</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#在master节点停掉heartbeat"><span class="nav-number">8.1.1.</span> <span class="nav-text">在master节点停掉heartbeat</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#查看slave日志是否能自动切换至slave节点"><span class="nav-number">8.1.2.</span> <span class="nav-text">查看slave日志是否能自动切换至slave节点</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
